package com.tutu.docker.controller;

import com.tutu.docker.entity.Books;
import com.tutu.docker.service.BooksService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Program: SpringBoot
 * @Description:
 * @Author: JK.TuTu
 * @Create: 2022-11-09 16:06
 **/
@RestController
@RequestMapping("books")
public class BooksController {
    /**
     * 服务对象
     */
    @Resource
    private BooksService booksService;


    @GetMapping
    public List<Books> books() {
        return booksService.queryAll();
    }

    /**
     * 根据id查询book
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Books book(@PathVariable("id") Integer id) {
        return booksService.queryById(id);
    }

    /**
     * 添加书籍
     *
     * @param books
     */
    @PostMapping
    public void save(@RequestBody Books books) {
        booksService.insert(books);
    }


    /**
     * 更新Books
     *
     * @param books
     * @param id
     */
    @PutMapping("/{id}")
    public void update(@RequestBody Books books, @PathVariable("id") Integer id) {
        books.setBookid(id);
        booksService.update(books);
    }

    /**
     * 删除书籍
     *
     * @param id
     */
    @DeleteMapping("/{id}")
    public void delete(@PathVariable("id") Integer id) {
        booksService.deleteById(id);
    }
}



